package SingleMachineArrangeImpl;

import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;

// 加权误工工件数问题
// 本问题是NP难的，且算法求出的解与最优解差异较大
public class WDAC extends SingleMachineArrange{
    List<Artifact> removed_artifacts;
    @Override
    public void solve() {
        artifacts = new ArrayList<>();
        removed_artifacts = new ArrayList<>();
        if(process==null||weight==null||due==null){
            process = new int[]{11, 9, 90};
            weight = new int[]{12, 9, 89};
            due = new int[]{100, 100, 100};
        }
        for (int i = 0; i < process.length; i++) {
            Artifact a = new Artifact();
            a.process = process[i];
            a.weight = weight[i];
            a.due = due[i];
            artifacts.add(a);
        }
        artifacts.sort(Comparator.comparingDouble(artifact -> -1.0 * artifact.weight / artifact.process));
        System.out.println(artifacts);
        getDelayedArtifacts(artifacts);
    }
    private void getDelayedArtifacts(List<Artifact> artifacts){
        int t = 0;
        int count = 0;
        int wu = 0;
        for (Artifact artifact : artifacts) {
            t += artifact.process;
            if (t > artifact.due) {
                System.out.println(artifact + "延误");
                count++;
                wu += artifact.weight;
            }
        }
        System.out.println("误工工件数：" + count);
        System.out.println("加权误工工件数：" + wu);
    }
}
